/*
 * Copyright (c) 2011.
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.graphoman.model;

import org.graphoman.gui.Viewport;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: daniil
 * Date: 11.10.11
 * Time: 9:43
 * To change this template use File | Settings | File Templates.
 */
public class Model {
    public List<State> states;
    public List<Transition> transitions;
    public Viewport viewport;

    public State selectedState = null;
    public State createTransitionFrom = null;
    public State createTransitionTo = null;
    public Transition selectedTransition = null;

    public Model() {
        viewport = new Viewport();
        states = new ArrayList<State>();
        transitions = new ArrayList<Transition>();
    }

    public static Model createTestModel() {
        Model model = new Model();

        model.states.add(new State("P", "Начало", 200, 65));
        model.states.add(new State("Q", "Середина", 375, 213));
        model.states.add(new State("R", "Конец", 408, 403));
        model.states.add(new State("H", "Авария", 150, 360));

        model.transitions.add(new Transition(model.states.get(0), model.states.get(1), "λ"));
        model.transitions.add(new Transition(model.states.get(1), model.states.get(2), "ψ"));
        model.transitions.add(new Transition(model.states.get(1), model.states.get(3), "β"));
        model.transitions.add(new Transition(model.states.get(3), model.states.get(0), "ω"));

        return model;
    }

    public List<Transition> getConnectedTransitions(State state) {
        List<Transition> result = new ArrayList<Transition>();
        for (Transition transition : transitions) {
            if (transition.from == state || transition.to == state) {
                result.add(transition);
            }
        }
        return result;

    }
}
